<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class upPhotos_manag extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->helper('form');
        $this->load->database();
        $this->load->helper('func');
        $this->load->model('alblum_process');
        $this->load->model('photos_process');
        $this->load->library('file_upload'); //引入类库
    }

    public function index() {
        $data["album_type_array"] = $this->album_type();
        // print_r($data["album_type_array"]);
        $this->load->view('admin/header_view');
        $this->load->view('admin/upPhotos_view', $data);
        $this->load->view('admin/footer_view');
    }

    public function add_album() {
        $post_array = $_POST;
        $config['upload_path'] = './uploads/album'; //设定上传存储路径
        $data = $this->file_upload->upLoadfile($config, "cover");

        if (isset($data)) {
            $siteurl = site_url(); //$siteurl .
            $config["source_image"] = $data["full_path"];
            $config["new_image"] = './uploads/album/thum';
            $this->file_upload->process_img($config);
            $_POST["cover"] = "{$data["file_name"]}";
        } else {
            $_POST["cover"] = "";
        }
        $this->alblum_process->add_album($_POST);
        redirect('admin/upPhotos_manag/');
        exit;
    }

    public function add_photo() {
        foreach ($_FILES as $key => $val) {
            $config['upload_path'] = './uploads/photos'; //设定上传存储路径
            $data = $this->file_upload->upLoadfile($config, $key);         
            if (isset($data)) {
               // print_r($data);
                //exit;
                $_POST["path"] = "{$data["file_name"]}";
                $config_img["source_image"] = $data["full_path"];
                $config_img["new_image"] = './uploads/photos/thum';
                $this->file_upload->process_img($config_img);
                $_POST["title"]=$data["client_name"];
                     $this->photos_process->add_photo($_POST);
            } else {

                continue;
            }
        }
redirect('admin/upPhotos_manag/');

    }

    private function album_type() {
        $album_type_array = $this->alblum_process->album_type_array_admin(1);
        return $album_type_array;
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */